<?php
class Nguyen_Controller_Action extends Zend_Controller_Action {
	var $request;
	public function loadTemplate($template){
		$templateConfig = BASE_PATH . '/public/templates/'.$template.'/template.ini';         
       
       $config = new Zend_Config_Ini($templateConfig, 'template');      
      
      $urlTemplate = $this->_request->getBaseUrl() . $config->url;
      $dirCss = $urlTemplate .  $config->dir->css;
      $dirJs = $urlTemplate . $config->dir->js;
      $dirImg = $urlTemplate . $config->dir->img;      
      $this->view->dirImg = $dirImg;
      $this->view->headTitle($config->title,true);
      foreach($config->file->css as $key => $item){         
         $this->view->headLink()->appendStylesheet($dirCss . $item);         
      }
      
      foreach($config->file->js as $key => $item){         
         $this->view->headScript()->appendFile($dirJs . $item,'text/javascript');   
      }
  //    $this->view->headMeta()->appendName('keywords', $info['meta']);
  //    $this->view->headMeta()->appendName('description', $info['description']);
      $layoutPath = $config->folder;
      $option = array ('layout' => 'index', 
                   'layoutPath' => $layoutPath );
      Zend_Layout::startMvc ( $option );      
    	$request = $this->_request->getParams();
    	$this->view->request = $request;
	}
	public function AdminOnly(){
		$auth = Zend_Auth::getInstance();		
		if($auth->hasIdentity()){
			$infoUser = $auth->getIdentity();
			if($infoUser->type != 1) {
				$this->_request->setModuleName('administrator');
				$this->_request->setControllerName('index');
				$this->_request->setActionName('noaccess');
			}
		}
	}
	public function StaffOnly(){
		$auth = Zend_Auth::getInstance();		
		if($auth->hasIdentity()){
			$infoUser = $auth->getIdentity();
			if($infoUser->type != 1 && $infoUser->type != 2) {
				$this->_request->setModuleName('administrator');
				$this->_request->setControllerName('index');
				$this->_request->setActionName('noaccess');
			}
		}
	}
	public function ModOnly(){
		$auth = Zend_Auth::getInstance();		
		if($auth->hasIdentity()){
			$infoUser = $auth->getIdentity();
			if($infoUser->type != 1 && $infoUser->type != 2 && $infoUser->type != 3) {
				$this->_request->setModuleName('administrator');
				$this->_request->setControllerName('index');
				$this->_request->setActionName('noaccess');
			}
		}
	}
}